﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace AspController
{
    public class ItemModelController : ApiController
    {
        ItemDAL itemDAL;
        public ItemModelController()
        {
            itemDAL = new ItemDAL();
        }
        // GET api/<controller>
        public IEnumerable<Item> Get()
        {
            return itemDAL.GetItem().ToList();
        }

        // GET api/<controller>/5
        public Item Get(int id)
        {
            var item = itemDAL.GetItem().ToList().Find(e => e.ItemID == id);
            return item;
        }

        // POST api/<controller>
        public void Post(Item item)
        {
            itemDAL.CreateItem(item);
        }

       
        // PUT api/<controller>/5
        public void Put(int id, Item item)
        {
            var itm = itemDAL.GetItem().ToList().Find(e => e.ItemID ==item.ItemID);
            itm = item;
            itemDAL.UpdateItem(itm);
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
            itemDAL.DeleteItem(id);
        }
    }
}